package com.ygqh.baby.service.impl;
import java.util.List;

import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminCustomMessage;
import  com.ygqh.baby.mapper.AdminCustomMessageMapper;
import  com.ygqh.baby.service.AdminCustomMessageService;

import  org.springframework.util.Assert;

import java.util.Arrays;

import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminCustomMessageExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminCustomMessageServiceImpl implements AdminCustomMessageService{
	
	@Autowired
	private AdminCustomMessageMapper adminCustomMessageMapper;
	
	@Override
	public List<AdminCustomMessage> find() {
		AdminCustomMessageExample example = new AdminCustomMessageExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminCustomMessageMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminCustomMessageExample example = new AdminCustomMessageExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminCustomMessageMapper.countByExample(example);
	}

	@Override
	public AdminCustomMessage findById(Long id) {
		return adminCustomMessageMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminCustomMessage adminCustomMessage) {
		return adminCustomMessageMapper.insertSelective(adminCustomMessage);
	}

	@Override
	public int update(AdminCustomMessage adminCustomMessage) {
		return adminCustomMessageMapper.updateByPrimaryKeySelective(adminCustomMessage);
	}

	@Override
	public ResultSet<AdminCustomMessage> search(QueryInfo queryInfo,Long userId) {
		List<AdminCustomMessage>  list =  adminCustomMessageMapper.selectSuper(queryInfo, userId);
		int count = adminCustomMessageMapper.countSuper(userId);
		ResultSet<AdminCustomMessage> resultSet = new ResultSet<AdminCustomMessage>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminCustomMessageExample example = new AdminCustomMessageExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminCustomMessage record = new AdminCustomMessage();
		record.setStatus(DataStatus.Delete);

		return adminCustomMessageMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminCustomMessage adminCustomMessage) {
		int r = 0;
		if(adminCustomMessage.getId() != null) {
			r = this.update(adminCustomMessage);
		}else {
			r = this.save(adminCustomMessage);
		}
		return r;
	}

	@Override
	public List<AdminCustomMessage> searchMessage(QueryInfo queryInfo,
			Long userId) {
		
		return adminCustomMessageMapper.selectSuper(queryInfo, userId);
	}

}

